﻿using Newtonsoft.Json;
using QingZhouLinYe_Web.DbContext;
using QingZhouLinYe_Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace QingZhouLinYe_Web.Ashxs
{
    /// <summary>
    /// getSheBeiByFangHuoDanWeiId 的摘要说明
    /// </summary>
    public class getSheBeiByFangHuoDanWeiId : IHttpHandler
    {
        private DbServices dbServices = new DbServices();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int authority = int.Parse(context.Request["authority"]);
            int fhdwid = int.Parse(context.Request["fhdwid"]);
            int sblxid = int.Parse(context.Request["sblxid"]);
            //List<SheBei> sbs = dbServices.GetSheBeis(authority, fhdwid,sblxid);
            //string sbs_str = JsonConvert.SerializeObject(sbs);
            //context.Response.Write(BaseClass.JsonIndentation(sbs_str));


            async Task<List<SheBei>> CallAsync()
            {
                //在另一个异步方法的调用方式
                // List<SheBei> sbs =await new TestServices().GetSheBeis(authority, fhdwid, sblxid); 
                return await new TestServices().GetSheBeis(authority, fhdwid, sblxid); 
            }
                context.Response.Write(BaseClass.JsonIndentation(JsonConvert.SerializeObject(CallAsync())));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}